﻿module Utils
open Types
open System.Drawing
open System.Windows.Forms
open MathNet.Numerics
open MathNet.Numerics.FSharp
open MathNet.Numerics.LinearAlgebra.Double
open System

let seed = Random()

//drawing start component
let f = new Form()
f.Width <- 600
f.Height <- 850
let graphics = f.CreateGraphics()
f.StartPosition <- FormStartPosition.CenterScreen
f.Show()

let white_color = Color.White

let draw_point (point_matrix : DenseMatrix) (prev_point_matrix : DenseMatrix) my_index =
  for j in [0..point_matrix.RowCount-1] do
    for i in [0..point_matrix.ColumnCount-1] do
      let prev_cmp = prev_point_matrix.[i,j]
      let cmp = point_matrix.[i,j]
      let i = i * 8
      let j = j * 8
      let brush = 
        if Math.Abs(prev_cmp - cmp) > 0.001  then
          new SolidBrush(Color.FromArgb(255,int (255.0 * cmp),0,0))          
        else
          if cmp < 0.2 then
            new SolidBrush(Color.FromArgb(255,0,0,int (255.0 * cmp)))
          elif cmp < 0.5 then
            new SolidBrush(Color.FromArgb(255,0,int (255.0 * cmp),int (255.0 * cmp)))
          elif cmp < 0.7 then
            new SolidBrush(Color.FromArgb(255,int (255.0 * cmp),0,int (255.0 * cmp))) 
          else
            new SolidBrush(Color.FromArgb(255,int (255.0 * cmp),int (255.0 * cmp),0))          

      do graphics.FillRectangle(brush, Rectangle(i + ((my_index % 4) * 150) + 4, 
                                                  j + 150 * (my_index / 4) + 4, 
                                                  8, 
                                                  8))


